import { getSystemIcon } from '@/api/utils/image';
import Login from '@/views/desktop/login/Login.vue';
import Browser from '@/views/widget/browser/Browser.vue';
import ImageVue from '@/views/widget/image/Image.vue';
import Notepad from '@/views/widget/notepad/Notepad.vue';
import type { NotepadViewMode } from '@/views/widget/notepad/data/types';
import Video from '@/views/widget/video/Video.vue';
import { ProgramEnum } from '../enum/windows.enum';
import { openWindow } from './window';

/**
 * 这里是插件列表参数文件
 * 再次封装Windows
 * 每个插件都有自己的私有属性
 */

/**
 * @description: 打开登录窗口
 */
export const openLogin = () => {
  openWindow({
    title: '登录',
    component: markRaw(Login),
    icon: getSystemIcon(`user.png`),
    id: ProgramEnum.LOGIN,
    w: 400,
    h: 600,
    maximize: false,
    resizable: false,
  });
};

/* 记事本回调 */
type NotepadCallback = {
  data: string;
  mode: string;
};
type NotepadConfig = {
  data: string;
  mode?: NotepadViewMode;
  /* 传入ID则多开记事本 */
  id?: string;
  save?: (arg: NotepadCallback) => any;
};
export const openNotepad = (config: NotepadConfig) => {
  openWindow({
    title: '记事本',
    component: markRaw(Notepad),
    id: config.id ? config.id : ProgramEnum.NOTEPAD,
    icon: getSystemIcon(`notepad.png`),
    data: {
      data: config.data,
      mode: config.mode || 'text',
      save: config.save,
    },
  });
};

type ImageType = {
  /* 图片路径 */
  src: string;
  /* 裁剪的大小，一旦设定，用户无法控制裁剪窗口的大小 */
  stencilSize?: {
    width: number;
    height: number;
  };
  /*
    执行保存的回调,返回一个处理后的图片
  */
  callback?: (src: string) => any;
  /* 模式：编辑|预览 */
  mode: 'view' | 'edit' | 'edit';
};
/* 打开图片 */
export const openImage = (config: ImageType) => {
  openWindow({
    title: '图片',
    component: markRaw(ImageVue),
    id: ProgramEnum.IMAGE,
    icon: getSystemIcon(`gallery.png`),
    dark: true,
    data: {
      src: config.src,
      stencilSize: config.stencilSize,
      callback: config.callback,
      mode: config.mode,
    },
  });
};
/* 打开视频 */
export const openVideo = (src: string) => {
  openWindow({
    title: '视频',
    component: markRaw(Video),
    id: ProgramEnum.VIDEO,
    icon: getSystemIcon(`movies.png`),
    dark: true,
    data: {
      src,
    },
  });
};

/* 打开浏览器 */
type BrowserProps = { src: string; type: 'html' | 'link' };

export const openBrowser = (config: BrowserProps) => {
  openWindow({
    title: '浏览器',
    component: markRaw(Browser),
    id: ProgramEnum.BROWSER,
    icon: getSystemIcon(`edge.png`),
    data: config,
  });
};
